<!DOCTYPE html>






  


<html class="theme-next pisces use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2"/>
<meta name="theme-color" content="#222">












<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />






















<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=6.2.0" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=6.2.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=6.2.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=6.2.0">


  <link rel="mask-icon" href="/images/logo.svg?v=6.2.0" color="#222">









<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '6.2.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="一、前言经过十几天的生产实习，学习了嵌入式开发的基本流程，从虚拟机到开发版，未知的事物总是促使我们去不断学习。伪入门嵌入式后，现在看一切硬件有关的东西，脑海都浮现嵌入式三个字。- _ - 放暑假的宿舍还是十分清净的，但是，你是否在电脑浏览网页的时候，看到一个个浮动的广告，没点广告还弹出一系列广告，心里不断谩骂该网站的前端开发者，不按套路出牌。在你用手机等移动设备浏览网页时，广告还是来了，它没改头换">
<meta property="og:type" content="article">
<meta property="og:title" content="小米路由器青春版折腾记">
<meta property="og:url" content="http://blog.bisondev.cn/2017/07/30/小米路由器青春版折腾记/index.html">
<meta property="og:site_name" content="Bison分享日志">
<meta property="og:description" content="一、前言经过十几天的生产实习，学习了嵌入式开发的基本流程，从虚拟机到开发版，未知的事物总是促使我们去不断学习。伪入门嵌入式后，现在看一切硬件有关的东西，脑海都浮现嵌入式三个字。- _ - 放暑假的宿舍还是十分清净的，但是，你是否在电脑浏览网页的时候，看到一个个浮动的广告，没点广告还弹出一系列广告，心里不断谩骂该网站的前端开发者，不按套路出牌。在你用手机等移动设备浏览网页时，广告还是来了，它没改头换">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://opl5tlfw9.bkt.clouddn.com/17-7-30/21766768.jpg">
<meta property="og:image" content="http://opl5tlfw9.bkt.clouddn.com/17-7-31/89106099.jpg">
<meta property="og:image" content="http://opl5tlfw9.bkt.clouddn.com/17-7-31/69809948.jpg">
<meta property="og:image" content="http://opl5tlfw9.bkt.clouddn.com/17-7-31/34625424.jpg">
<meta property="og:updated_time" content="2017-07-30T16:57:41.093Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="小米路由器青春版折腾记">
<meta name="twitter:description" content="一、前言经过十几天的生产实习，学习了嵌入式开发的基本流程，从虚拟机到开发版，未知的事物总是促使我们去不断学习。伪入门嵌入式后，现在看一切硬件有关的东西，脑海都浮现嵌入式三个字。- _ - 放暑假的宿舍还是十分清净的，但是，你是否在电脑浏览网页的时候，看到一个个浮动的广告，没点广告还弹出一系列广告，心里不断谩骂该网站的前端开发者，不按套路出牌。在你用手机等移动设备浏览网页时，广告还是来了，它没改头换">
<meta name="twitter:image" content="http://opl5tlfw9.bkt.clouddn.com/17-7-30/21766768.jpg">






  <link rel="canonical" href="http://blog.bisondev.cn/2017/07/30/小米路由器青春版折腾记/"/>



<script type="text/javascript" id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>小米路由器青春版折腾记 | Bison分享日志</title>
  









  <noscript>
  <style type="text/css">
    .use-motion .motion-element,
    .use-motion .brand,
    .use-motion .menu-item,
    .sidebar-inner,
    .use-motion .post-block,
    .use-motion .pagination,
    .use-motion .comments,
    .use-motion .post-header,
    .use-motion .post-body,
    .use-motion .collection-title { opacity: initial; }

    .use-motion .logo,
    .use-motion .site-title,
    .use-motion .site-subtitle {
      opacity: initial;
      top: initial;
    }

    .use-motion {
      .logo-line-before i { left: initial; }
      .logo-line-after i { right: initial; }
    }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Bison分享日志</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">I'm not perfect,but I keep trying</p>
      
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>




<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">
    <a href="/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-about">
    <a href="/about/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">
    <a href="/tags/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />标签</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">
    <a href="/categories/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-th"></i> <br />分类</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">
    <a href="/archives/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />归档</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-schedule">
    <a href="/schedule/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-calendar"></i> <br />日程表</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-sitemap">
    <a href="/sitemap.xml" rel="section">
      <i class="menu-item-icon fa fa-fw fa-sitemap"></i> <br />站点地图</a>
  </li>

      
      
    </ul>
  

  

  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://blog.bisondev.cn/2017/07/30/小米路由器青春版折腾记/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Bison Qin">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Bison分享日志">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">小米路由器青春版折腾记
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2017-07-30 22:56:06" itemprop="dateCreated datePublished" datetime="2017-07-30T22:56:06+08:00">2017-07-30</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2017-07-31 00:57:41" itemprop="dateModified" datetime="2017-07-31T00:57:41+08:00">2017-07-31</time>
              
            
          </span>

          

          
            
          

          
          
             <span id="/2017/07/30/小米路由器青春版折腾记/" class="leancloud_visitors" data-flag-title="小米路由器青春版折腾记">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数：</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="一、前言"><a href="#一、前言" class="headerlink" title="一、前言"></a>一、前言</h1><p>经过十几天的生产实习，学习了嵌入式开发的基本流程，从虚拟机到开发版，未知的事物总是促使我们去不断学习。伪入门嵌入式后，现在看一切硬件有关的东西，脑海都浮现嵌入式三个字。- _ -</p>
<p>放暑假的宿舍还是十分清净的，但是，你是否在电脑浏览网页的时候，看到一个个浮动的广告，没点广告还弹出一系列广告，心里不断谩骂该网站的前端开发者，不按套路出牌。在你用手机等移动设备浏览网页时，广告还是来了，它没改头换面，没错，它的大小可能都还没有适配好，戳关闭按钮也关不掉的那种，你可能在心里又不经吐槽网页的兼容性。当你追一部大剧的时候，你可能会体会到广告两小时，正片5分钟的痛感，恐怕你就在这种生活场景中发现了JS的强大。</p>
<p>好啦，不扯了。对于非夏天晚上断电的宿舍来说，小米路由器青春版无疑是非常实用的。体积小，丢在角落没烦恼；价格便宜，学生党买得起；配备Miscro USB，充电宝也能供电，不惧断电。呃呃呃，没收广告费。小米路由器青春版搭载的是基于OpenWRT深度定制的智能路由器操作系统MiWiFi ROM，说到底，就是linux啦，就是嵌入式的体现吧。</p>
<h1 id="二、进入路由器内部"><a href="#二、进入路由器内部" class="headerlink" title="二、进入路由器内部"></a>二、进入路由器内部</h1><p>这里说的内部不是硬件的内部，我们学软件的，就在能不拆开硬件解决问题就不拆。既然是类似于linux的系统，那应该有命令行才像呀，那我们就找找。小米的产品还是挺开放的，路由也是有开放平台的。<a href="http://www1.miwifi.com/miwifi_open.html" target="_blank" rel="noopener">MiWifi开放平台</a></p>
<p>在开放平台中，我们很容易就能找到”开启SSH工具”，玩过服务器的都知道，用SSH的方式，我们可以通过命令行的方式与系统进行连接，路由器系统也不例外。出于安全考虑，路由器系统都会把SSH关了，自然我们就不容易进到路由器的系统中。在寻找官方的开启SSH工具的过程中我们会发现，我们的小米路由器青春版其实是没有官方的开启工具的。<br><img src="http://opl5tlfw9.bkt.clouddn.com/17-7-30/21766768.jpg" alt=""><br>这个时候在查阅网友的帖子发现，在旧版的开发版系统中，是可以直接通过修改路由管理器的请求地址的特定参数键值对，而改变系统参数。 </p>
<p>下面引用修改的方法：  </p>
<ol>
<li><p>登录路由管理界面<br>地址栏输入192.168.31.1，输入账号密码后，地址栏会多了一串参数，类似于<br><code>http://192.168.31.1/cgi-bin/luci/;stok=075a9192918557c27cdbcae2175281d9/web/home#router</code>   </p>
</li>
<li><p>更改管理员密码和系统的root密码<br>将以上的地址URL中<code>/web/home#router</code>改成<code>/api/xqsystem/set_name_password?oldPwd=当前路由的密码&amp;newPwd=新的路由密码</code>，<br>然后查看网页的返回结果，如果返回的JSON字符串是<code>{&quot;code&quot;:0}</code>，那就任务完成，如果返回是说参数错误的，那十有八九是系统是新版，小米官方修补了这个漏洞。<br>解决办法就是刷回旧版系统，鉴于找资源麻烦，这里做了收集，以下是官方的小米路由器青春版的2.1.22的开发版ROM。  <a href="http://pan.baidu.com/s/1bpvnY8Z" title="链接" target="_blank" rel="noopener">链接</a>，密码：yred（刷机方法由官方的路由管理界面，上传本ROM包，自动升级即可）</p>
</li>
<li><p>启用路由的telnet登录方式<br>同第二步中的修改网址URL，把<code>/web/home#router</code>改为<code>/api/xqnetwork/set_wifi_ap?ssid=xiaomi&amp;encryption=NONE&amp;enctype=NONE&amp;channel=1%3B%2Fusr%2Fsbin%2Ftelnetd</code>，然后查看返回的JSON数据<code>{&quot;msg&quot;:&quot;未能连接到指定WiFi(Probe timeout)&quot;,&quot;code&quot;:1616}</code>，返回码有可能不同，但是这里已经可以通过telnet的方式来登录路由器了</p>
</li>
<li><p>用putty的telnet方式登录<br>下载一个<a href="http://pan.baidu.com/s/1hsquhxy" target="_blank" rel="noopener">Putty</a> ，密码：gqxa。然后打开选填以下参数，连接类型：telnet;主机名称：192.168.31.1.打开后看到login，输入root，密码则为以上第二步中修改的新密码。然后依次执行下面的三条指令：<br>4.1 <code>sed -i &quot;:x;N;s/if \[.*\; then\n.*return 0\n.*fi/#tb/;b x&quot; /etc/init.d/dropbear</code><br>4.2 <code>/etc/init.d/dropbear start</code><br>4.3 <code>nvram set ssh_en=1; nvram commit</code>  </p>
</li>
</ol>
<h1 id="三、进阶"><a href="#三、进阶" class="headerlink" title="三、进阶"></a>三、进阶</h1><ol>
<li><p>备份原厂bin（可选）<br>1.1 打开WINSCP文件协议SCP 主机名192.168.31.1 端口号22用户名root密码admin（此处由上面设置了什么新密码决定） 。有错误提示就点击更新或者确定<br>1.2 打开putty 主机名称192.168.31.1 端口号22 连接类型ssh,有错误提示就点击更新或者确定<br>输入命令 <code>cat /proc/mtd</code><br><img src="http://opl5tlfw9.bkt.clouddn.com/17-7-31/89106099.jpg" alt=""><br>可以看到上面有十个固件和分区，看名字可以知道第一个mtd0固件包含已全部分区的数据（All），第二个是Bootloader，刷过机的都会对这个有映像。<br><code>dd if=/dev/mtd0 of=/tmp/all.bin</code>，这是表示备份第一个固件到tmp文件夹的all.bin文件中，另外类似的命令有：<code>dd if=/dev/mtd1 of=/tmp/bootloader.bin</code>等。（需要注意的是，路由器的空间很小，尽可能备份之后，通过winscp下载并删了路由中的文件，以防空间不足）</p>
</li>
<li><p>刷入breed<br>通过WinScp把breed.bin（地址：<a href="http://pan.baidu.com/s/1nuY9aPj" target="_blank" rel="noopener">http://pan.baidu.com/s/1nuY9aPj</a>，密码：x1qa）传入到/tmp中。然后通过Putty，输入命令<code>mtd -r write /tmp/breed.bin Bootloader</code>写入Breed，刷入成功后会提示重启，putty和WinScp都会断开，关闭了即可。</p>
</li>
<li><p>进入breed控制台<br>把电源拔了，使路由关机，用牙签或者其他尖锐物戳着reset键，然后插上插头，待路由器后方的灯（非正前方的灯）闪烁时松开reset键即可，然后用一条网线把电脑和路由器的WAN口相连接，打开浏览器访问192.168.1.1，即可进入breed控制台了。</p>
</li>
<li><p>刷机（可选）<br>刷机只是尝试不同的系统，和不同的功能。在本次尝鲜中，刷入了PandoraBox（潘多拉魔盒）系统，链接：<a href="http://pan.baidu.com/s/1cKs4W2" target="_blank" rel="noopener">http://pan.baidu.com/s/1cKs4W2</a> 密码：dygy。刷入完成后最简单的测试方法就是在地址栏输入192.168.1.1测试路由是否开启成功，成功的话，会进入PandoraBox的管理界面中。</p>
</li>
</ol>
<h1 id="四、基本使用"><a href="#四、基本使用" class="headerlink" title="四、基本使用"></a>四、基本使用</h1><ol>
<li><p>设置管理界面样式<br>系统-&gt;系统-&gt;语言和界面-&gt;主题，我是选择了Bootstrap样式，这样好看多了</p>
</li>
<li><p>设置PPoE上网方式<br>网络-&gt;接口-&gt;WAN-&gt;修改-&gt;协议，选择PPPoE后，点击切换协议，然后在PAP/CHAP用户名中输入PPoE的账号，在密码中输入上网的密码，然后直接点击保存&amp;应用，就会生效</p>
</li>
<li><p>添加广告屏蔽插件<br>系统-&gt;软件包-&gt;刷新列表-&gt;可用软件包-&gt;选择L-&gt;安装“luci-app-adbyby”。<br><img src="http://opl5tlfw9.bkt.clouddn.com/17-7-31/69809948.jpg" alt=""></p>
</li>
</ol>
<p>安装完之后刷新界面，会在服务-&gt;广告屏蔽中发现广告屏蔽的状态<br><img src="http://opl5tlfw9.bkt.clouddn.com/17-7-31/34625424.jpg" alt=""></p>

      
    </div>

    

    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/07/28/ListView的优化/" rel="next" title="ListView的优化">
                <i class="fa fa-chevron-left"></i> ListView的优化
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/12/05/JaveWeb环境配置/" rel="prev" title="JaveWeb环境配置">
                JaveWeb环境配置 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">Bison Qin</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">13</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">4</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">8</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          

          

          
          

          
          

          
            
          
          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#一、前言"><span class="nav-number">1.</span> <span class="nav-text">一、前言</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#二、进入路由器内部"><span class="nav-number">2.</span> <span class="nav-text">二、进入路由器内部</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#三、进阶"><span class="nav-number">3.</span> <span class="nav-text">三、进阶</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#四、基本使用"><span class="nav-number">4.</span> <span class="nav-text">四、基本使用</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Bison Qin</span>

  

  
</div>




  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动 v3.7.1</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/theme-next/hexo-theme-next">NexT.Pisces</a> v6.2.0</div>




        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=6.2.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=6.2.0"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=6.2.0"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=6.2.0"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=6.2.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=6.2.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=6.2.0"></script>



  



	





  





  










  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("M90nbI9KgVkqdeNl4kIE1aY4-gzGzoHsz", "3I8HRy0nT1nMlMw7enfvrnu5");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            
              var $element = $(document.getElementById(url));
              $element.find('.leancloud-visitors-count').text(counter.get('time'));
            
            counter.save(null, {
              success: function(counter) {
                
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            
              var $element = $(document.getElementById(url));
              $element.find('.leancloud-visitors-count').text('Counter not initialized! See more at console err msg.');
              console.error('ATTENTION! LeanCloud counter has security bug, see here how to solve it: https://github.com/theme-next/hexo-leancloud-counter-security. \n But you also can use LeanCloud without security, by set \'security\' option to \'false\'.');
            
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  

  
  

  

  

  

  

  

</body>
</html>
